var member = require('../models/userModel');
var product = require('../models/productModel');
var _ = require('underscore');
var ko = require('knockout');
var template = require('template');
var tpl = require('../templates/member.tpl');
var hbs = require('../templates/member.hbs');

if (window.console && window.console.log) {
    window.console.log('测试member');
    window.console.log(member);
    window.console.log(_);
    window.console.log(ko);
    window.console.log(template);
    window.console.log(hbs);
}

setTimeout(function () {
    document.getElementById('root').innerHTML = 'this is a member page.';
    $(document).pjax('a', '#pjax-container');
}, 3000);

setTimeout(function () {
    var arr = [1, 2, 3, 4, 5, 6];
    var even = _.find(arr, function (num) {
        return num % 2 === 0;
    });
    var str = '数组元素：' + arr.join(',') + "even值：" + even;
    $('#underId').show().find('span').eq(1).text(str);
}, 4000);

setTimeout(function () {
    function ApplyViewModel() {
        var self = this;
        self.items = ko.observableArray([1, 2, 3, 4, 5]);
        self.spamFlavor = ko.observableArray();
        self.spamFlavors = ko.observableArray();
    }
    var vm = new ApplyViewModel();
    //vm.spamFlavor('cherry');
    vm.spamFlavor.subscribe(function (x) {
        $('#radioSelect').show().find('i').text(x);
    });

    vm.spamFlavors.subscribe(function (x) {
        if (x.length > 0) {
            $('#checkSelect').show().find('i').text(x.join(','));
        }else{
             $('#checkSelect').hide().find('i').text('');
        }
    });

    var ele = $('#koId')[0];
    ko.cleanNode(ele);
    ko.applyBindings(vm, ele);
    $('#koId').show();
}, 5000);


setTimeout(function () {
    var render = template.compile(tpl);
    var html = render(product);
    $('#tplId').html(html).show();
}, 6000);
